<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/product/product.field.class.php');
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/product/product.field.value.class.php');

class ProductFieldsBase {
	var $pfObj = NULL;
	var $pfvObj = NULL;
	
	//product id
	var $pid = 0;
	
	//constructor
	function ProductFieldsBase() {
		$this->pfObj = new ProductFieldBase();
		$this->pfObj->format = true;
		
		$this->pfvObj = new ProductFieldValueBase();
		$this->pfvObj->format = true;
	}
	
	function setPID($pid) {
		$this->pid = $pid;
	}
	
	function setProductID($pid) {
		$this->pid = $pid;
	}	
	
	//methods
	function getFields() {
		return $this->pfObj->getItems('', 0, false);
	}
	
	function getFieldsValues() {
		$items = array();
		$fields = $this->pfObj->getItems('', 0, false);
		$values = $this->pfvObj->getItems(array('pid' => $this->pid), 0, false);
		$values = $this->pfvObj->setListKey($values, 'fid');
		
		for($i=0, $n=sizeof($fields); $i<$n; $i++) {
			$items[] = array('item' => $fields[$i], 'value' => $values[$fields[$i]['id']]);
		}
		
		return $items;
	}
}
//
?>